package dynamic_hybrid;

import java.util.Random;


public class CalculateResultVector extends Matrix
{

	private int ROW,COLUMN , BITNUMBER ;
		
	private int[][]  HYBRIDMATRIX , INITIALCOLUMNVECTOR , RESULTVECTOR ;
	
	
	public CalculateResultVector()
	{
		
		
		
	}
	
	
	public int[][] getResultVector(int bitnumber,int [][] hybridMatrix)
	{
		this.ROW          = hybridMatrix.length      ;
		this.COLUMN       = hybridMatrix[0].length   ;
		this.BITNUMBER    = bitnumber                ;
				
						
		HYBRIDMATRIX        = hybridMatrix ; 
		INITIALCOLUMNVECTOR = getInitialColumnVector()       ; 
		RESULTVECTOR        = this.getVector() ;
		return RESULTVECTOR ;
	}
	
	
	private int[][] getInitialColumnVector()
	{
	    int ROW=this.ROW, COLUMN=1;
	    
	    int[][] result = new int[ROW][COLUMN];
	   // int[][] result2 = { {0},{1},{1},{0},{0},{1},{0},{0},{1},{0},{1},{0},{0},{1},{0},{1},{0},{0},{1},{0},{0},{1},{1},{1},{0},{1},{0},{0},{1},{1},{0},{1},{1},{1},{1},{1},{1},{1},{0},{1},{1},{0},{0},{0},{1},{0},{0},{1},{1},{0},{0},{0},{1},{0},{0},{0},{1},{1},{1},{1},{0},{1},{1},{1},{0},{0},{0},{0},{0},{0},{0},{0},{0},{1},{0},{0},{0},{1},{0},{0},{0},{1},{1},{0},{1},{1},{0},{1},{1},{0},{1},{0},{0},{0},{0},{0},{1},{0},{0},{0},{0},{0},{1},{1},{0},{0},{1},{0},{0},{1},{0},{0},{1},{1},{1},{1},{1},{0},{1},{1},{0},{0},{1},{0},{0},{1},{1},{1},{0},{0},{0},{0},{0},{1},{1},{1},{1},{0},{0},{1},{1},{1},{1},{1},{0},{1},{0},{1},{0},{0},{1},{1},{0},{0},{1},{1},{0},{0},{0},{1},{1},{1},{0},{0},{0},{0},{0},{0},{0},{1},{0},{0},{0},{1},{1},{1},{0},{1},{1},{0},{0},{1},{1},{1},{0},{1},{0},{0},{0},{1},{1},{0},{1},{1},{1},{0},{1},{1},{0},{1},{1},{1},{0},{1},{1},{0},{0},{1},{0},{0},{0},{0},{0},{0},{0},{1},{1},{1},{1},{0},{0},{0},{1},{0},{1},{0},{1},{1},{0},{0},{1},{1},{0},{0},{0},{0},{1},{1},{1},{0},{1},{0},{0},{1},{1},{1},{0},{0},{1},{1},{0},{0},{0},{0},{0},{0},{1},{1},{0},{1},{1},{0},{1},{0},{0},{0},{1},{0},{0},{0},{1},{1},{0},{0},{0},{0},{1},{1},{0},{0},{0},{1},{0},{1},{1},{0},{0},{0},{1},{1},{0},{1},{0},{1},{0},{0},{1},{1},{1},{1},{1},{0},{0},{0},{0},{1},{1},{0},{0},{1},{1},{0},{0},{1},{1},{0},{0},{0},{0},{0},{1},{0},{0},{0},{1},{0},{1},{0},{0},{1},{1},{0},{1},{0},{0},{0},{1},{0},{1},{0},{0},{0},{0},{0},{0},{1},{1},{1},{0},{0},{0},{0},{0},{0},{1},{0},{0},{0},{0},{1},{0},{1},{1},{1},{0},{1},{1},{1},{1},{0},{1},{1},{0},{1},{1},{1},{0},{1},{0},{1},{0},{1},{0},{0},{1},{0},{1},{0},{1},{0},{0},{1},{1},{1},{1},{0},{1},{1},{0},{0},{0},{0},{1},{0},{0},{0},{1},{1},{1},{1},{1},{0},{0},{1},{0},{1},{1},{1},{0},{1},{1},{1},{1},{1},{0},{1},{0},{1},{1},{0},{0},{0},{0},{0},{1},{0},{0},{0},{0},{1},{1},{0},{0},{1},{0},{0},{0},{0},{1},{1},{0},{0},{1},{1},{1},{0},{0},{1},{1},{1},{0},{0},{1},{0},{1},{1},{1},{1},{0},{1},{0},{1},{1},{0},{1},{0},{0},{1},{1},{1},{0},{0},{1},{0},{1},{0},{0},{0},{0},{1},{1},{0},{0},{0},{0},{1},{1},{0},{1},{1},{1},{0},{1},{1},{1},{0},{1},{1},{0},{1},{0}, {0}} ; 
	   //int[][] result2 = { {1},{0},{1},{0},{0},{0},{1},{1},{1},{0},{1},{1},{1},{0},{0},{0}};
	    Random  generator = new Random() ;
	    for(int i = 0 ; i<ROW;i++)
	        result[i][0] = generator.nextInt(2) ; 
	    
	    return result ;
	}
	
	
	private  int[][] getVector()
	{
	    int VECTORLENGTH = this.BITNUMBER ;
	    
	    int[][] result =  new  int[1][VECTORLENGTH] ;
	   
	    int[][] TMPRESULT = this.INITIALCOLUMNVECTOR ;
	    
	   	    
	    for(int i = 0 ; i < VECTORLENGTH;i++)
	    {
	        TMPRESULT = this.multiply(HYBRIDMATRIX, TMPRESULT) ;	        
	        result[0][i] = TMPRESULT[10][0] ;
	       
	    }
	    
	    return result ;
	}
	
	 private  int[][] multiply(int[][] m1, int[][] m2)
	  {
	    int m1rows = m1.length;
	    int m1cols = m1[0].length;
	    int m2rows = m2.length;
	    int m2cols = m2[0].length;
	    if (m1cols != m2rows)
	      throw new IllegalArgumentException("matrices don't match: " + m1cols + " != " + m2rows);
	    int[][] result = new int[m1rows][m2cols];
	
	    // multiply
	    for (int i=0; i<m1rows; i++)
	      for (int j=0; j<m2cols; j++)
	        for (int k=0; k<m1cols; k++)
	        result[i][j] = (result[i][j]+(m1[i][k] * m2[k][j]))%2;
	
	    return result;
	  }
	
	 
	 public String toString()
	 {
			    
			printMatrix(this.RESULTVECTOR, "RESULT VECTOR FOR "+this.BITNUMBER +" of bits") ;
			
			return " " ;
	}
	
	
	
	
}
